const {drawNode,drawText,drawLine1} = require("../../api/circuitMonitorApi");
// const {drawNode} = require("../api/api");

//线朝向
// let CONNECTOR = {
//     LEFT: 1,
//     UP: 2,
//     RIGHT: 3,
//     DOWN: 4
// }
//
// //箭头朝向
// let DIRECTION = {
//     LEFT: 1,
//     UP: 2,
//     RIGHT: 3,
//     DOWN: 4
// }

//框形状
let SHAPE = {
    RECTANGULAR: 0,
    DIAMOND: 1,
    ELLIPSE: 2,
}

//状态
const STATUS = {
    TRUE: {
        color: "#42b983" //green
    },
    FALSE: {
        color: "red"
    },
    STOP: {
        color: "#FFFF00" //yellow

    },
    DEFAULT: {
        color: "#f3f5f6" //gray
    }
}


let globalSettins = {
    fontSize: 15, //字号，具体使用数字还是字符串可根据程序更改
    lineWordCount: 10, //单行字数
    lineSpace: 5, //文字行间距
    lineWidth: 2, //线宽
    whiteSpace: 15, //文字留白
    rowSpace: 60, //框行间距，单位px
    columnSpace: 60, //框列间距，单位px
    font: "15px 微软雅黑", //字体配置
    nodewidth:50,
    nodehight:30,
    startNodewidth: 5,//起始和结尾两端的竖线的宽度
    startNodehight: 50,//起始和结尾两端的竖线的高度
    startNodeLineWordCount: 5,//起始节点(imagename)的每行文字个数
    imageSpace: 5,//文字和节点之间的间隙
};
// 节点和连线
let nodes = []; //nodes里存放的就是各个myNode对象
let edges = []; //edges里存放的就是各个myEdges对象
// let currentNodeId = 0;
// let varMap = [];
// let nodeElemChange = -1;
let rowInterval = [];//每行节点之间的间隔
let columnInterval = [];//每列节点之间的间隔

let defaultConfig = {
    text: {
        content: "", //框内文字或者线上文字的默认值为空
        align: "left", //左对齐
        fontSize: globalSettins.fontSize, //字体大小
        color: "black" //字颜色
    },
    lineWidth: globalSettins.lineWidth, //线宽
    color: "black", //框颜色
    status: STATUS.DEFAULT //框状态
}
function clearDraw(){
    nodes = [];
    edges = [];
    // varMap = [];
    // prePosition = 0;
    // currentNodeId = 0;
}
function initCanvas(canvasName, w = 1000, h = 500) {
    let canvas = document.getElementById(canvasName);
    // console.log("2222",canvasName,canvas);
    //画布size
    canvas.width = w;
    canvas.height = h;
    return canvas;
}

function myNode(id, x, y, w, h, tx, ty, tw, th, type = SHAPE.RECTANGULAR, varName = null, text = null, config = defaultConfig) {
    this.id = parseInt(id);
    this.x = parseInt(x);
    this.y = parseInt(y);
    this.w = parseInt(w);
    this.h = parseInt(h);
    this.tx = parseInt(tx);
    this.ty = parseInt(ty);
    this.tw = parseInt(tw);
    this.th = parseInt(th);
    this.text = text;


    // this.ty = parseInt(ty);

    this.connector_left = null;
    this.connector_up = null;
    this.connector_right = null;
    this.connector_down = null;
    this.nextNodes =  [];

    this.type = parseInt(type); //0:矩形 1:钻石型 2: 带圆弧矩形
    this.config = config;

    this.varName = varName;
    //
    this.status = 0;
    this.backgroundColor = this.config.status.color;
    //this.draw(type);
    //this.drawText(config);
    nodes.push(this);
}


function myEdge(start_x, start_y, middle_x, middle_y, end_x, end_y, startConnector, endConnector, config = defaultConfig) {
    this.startConnector = startConnector;
    this.endConnector = endConnector;
    this.start_x = start_x;
    this.start_y = start_y;
    this.middle_x = middle_x;
    this.middle_y = middle_y;
    this.end_x = end_x;
    this.end_y = end_y;
    // this.arrow_direction = this.startConnector - this.endConnector;
    this.config = config;


    edges.push(this);
}
/*根据传入字符串的长度，及全局设置中的字体大小和单行长度计算
  Node中text的宽度和高度,并返回
*/
function calNodeTextSize(stringLen,lineWordCount,fontSize) {

    let h;
    let w;
    let whiteSpace = globalSettins.whiteSpace; //框内文字的留白区大小
    // let fontSize = globalSettins.fontSize; //文字的大小
    // let lineWordCount = globalSettins.lineWordCount; //一行最多字数
    let lineSpace = globalSettins.lineSpace; //文字的行间距

    // 字数小于lineWordCount
    if (stringLen <= lineWordCount) {
        w = stringLen * fontSize + whiteSpace;
        h = fontSize + whiteSpace;
    } else {
        // 字数大于lineWordCount ，需要换行
        w = lineWordCount * fontSize + whiteSpace;
        // 高度向上取整
        h = Math.ceil(stringLen / lineWordCount) * fontSize +
            Math.ceil(stringLen / lineWordCount - 1) * lineSpace +
            whiteSpace;
    }
    // console.log("文字高和宽",h,w);
    return {
        height: h,
        width: w
    }
}

//计算每行节点之间的间隔（即文字的最大高度加上偏移）
//rowInterval[0].height:在第一行节点上面的文字高度+偏移
//rowInterval[1].height:在第一行节点下面的文字高度+偏移
//rowInterval[N].height:在第N-1行节点下面的文字高度+偏移
function calNodeInterval(nodes){
    //每列宽度间隔（固定）,max( 最大的文字宽度 , 节点方框的宽度 )
    let textMaxWidth = calNodeTextSize(globalSettins.lineWordCount,globalSettins.lineWordCount,globalSettins.fontSize);
    let numcolumnInterval = 0;
    if(textMaxWidth.width > globalSettins.nodewidth)
    {
        numcolumnInterval = textMaxWidth.width + globalSettins.whiteSpace;
    }else{
        numcolumnInterval = globalSettins.nodewidth;
    }
    // console.log("asdidh ",textMaxWidth.width,nodes[0],numcolumnInterval);

    //每行高度间隔
    nodes.forEach(function(item) {
        while (rowInterval.length <= item.row + 1) {
            rowInterval.push(0);
            rowInterval.push(0);
        }
        while (columnInterval.length <= item.column) {
            columnInterval.push(0);
            columnInterval.push(0);
        }
        if(item.row == 0 && item.nodeId % 2 == 0) {
            if(rowInterval[0] < item.TextSize.height)
                rowInterval[0] = item.TextSize.height;
        }else if(item.row == 0 && item.nodeId % 2 == 1){
            if(rowInterval[1] < item.TextSize.height)
                rowInterval[1] = item.TextSize.height;
        }else{
            if(rowInterval[item.row + 1] < item.TextSize.height)
                rowInterval[item.row + 1] = item.TextSize.height;
        }
        columnInterval[item.column] = numcolumnInterval;
    });
}
//计算每张图的高度，用于设置每个canvas的高度
function calImageHeight(nodes,m){
    return nodes[nodes.length-1].y + nodes[nodes.length-1].h + rowInterval[rowInterval.length-1] + 10 * m;

}
//计算节点的坐标、节点文字的坐标
function calNodeLocation(imageName, nodes, nodeHeights, nodeWidthes, maxWidthes){
    let m = 10;//从第一行留出的间隙
    let startx = 0;//第一列node的左顶点x值
    let imageNameSize= calNodeTextSize(imageName.length, globalSettins.startNodeLineWordCount, globalSettins.fontSize);//一行只显示一行节点文字的一半数量的imagename
    let startNodeInterval = m + imageNameSize.width + m + globalSettins.startNodewidth + globalSettins.columnSpace;//为起始的imageName和竖线留出空间
    // console.log("startx:",startx);
    nodes.forEach(function(item) {
        //计算y值
        item.y = 0;
        if(item.row == 0){
            //第0行的y偏移为第一行节点上方的文字y+文字高度+间隙m
            item.y = m + rowInterval[0] + m ;
            // console.log("第一列节点的y值",item.y,rowInterval[0]);
            if(item.nodeId % 2 == 0)
            {
                //第0行文字的左顶点Y
                item.ty = item.y - item.TextSize.height - m;
                // console.log("第一行节点的y值",item.y,item.ty,item.TextSize.height,m);
            }else{
                //第0行文字的左顶点Y,等于框框y+框框高度+偏移间隙m
                item.ty = item.y + nodeHeights[item.row] + m ;
            }

        }else{
            //第1行及以后的y为前面的文字高度累加和框框高度累加
            item.y = rowInterval[0] + 2 * m;
            for(let i = 0; i < item.row; ++i){
                item.y += rowInterval[i+1] + nodeHeights[i] + 2 * m;
            }
            //第1行及以后的文字的左顶点Y,等于框框y+框框高度+偏移间隙m
            item.ty = item.y + nodeHeights[item.row] + m ;
        }
        //计算x值
        item.x = 0;

        if(item.column == 0 && nodeWidthes[item.column] <  maxWidthes[item.column]){
            //第0列，方框宽度小于文字宽度时
            // item.x = 0.5 * maxWidthes[item.column] ;
            // startx =  item.x;
            // item.tx = 0.5 * nodeWidthes[item.column] ;//当框的起点x设为0.5*文字宽度时，文字的起点x为0.5*框的宽度
            // console.log("第0列节点：",maxWidthes[item.column],nodeWidthes[item.column]);
            item.tx = startNodeInterval + m + 0.5 * maxWidthes[item.column];
            item.x = item.tx - 0.5 * maxWidthes[item.column] + 0.5 * (maxWidthes[item.column] - nodeWidthes[item.column]);
            startx =  item.x;
            // console.log("第0列节点左上：",item.x);
        }else if(item.column == 0 && nodeWidthes[item.column] >=  maxWidthes[item.column]){
            //第0列，方框宽度大于等于文字宽度时
            // console.log("第0列节点：",maxWidthes[item.column],nodeWidthes[item.column])
            item.x = startNodeInterval + m;
            startx =  item.x;
            item.tx = m + 0.5 *(nodeWidthes[item.column] -  maxWidthes[item.column]) + 0.5 * maxWidthes[item.column];
        }else{
            //其他列
            item.x = startx;
            for(let i = 0; i < item.column; ++i){
                item.x += nodeWidthes[item.column] + columnInterval[item.column];
            }
            if(nodeWidthes[item.column] <  maxWidthes[item.column]) {
                //方框宽度小于文字宽度时
                item.tx = item.x - 0.5 * (maxWidthes[item.column] - nodeWidthes[item.column]) + 0.5 * maxWidthes[item.column];
            }else{
                //方框宽度大于文字宽度时
                item.tx = item.x + 0.5 * (nodeWidthes[item.column] - maxWidthes[item.column]) + 0.5 * maxWidthes[item.column];
            }
        }
    });
}

function findNodeInfo(imageName, nodes, rowLocations, columnLocations, maxWidthes, maxHeights, nodeWidthes, nodeHeights) {
    let m = 30; // 外边距
    // console.log("111");
    nodes.forEach(function(item) {
        while (rowLocations.length <= item.row) {
            rowLocations.push(0);
            nodeHeights.push(0);
        }
        while (columnLocations.length <= item.column) {
            columnLocations.push(0);
            nodeWidthes.push(0);
        }
        //固定node的宽和高
        nodeWidthes[item.column] = globalSettins.nodewidth;
        nodeHeights[item.row] = globalSettins.nodehight;
        // console.log(item);
        item.TextSize= calNodeTextSize(item.text.length,globalSettins.lineWordCount,globalSettins.fontSize);
        // item.tw = item.TextSize.width
        //  console.log("222 ",item.TextSize);


        //rowLocations、columnLocations存放每行节点文字的高度和每列节点文字的宽度
        if (rowLocations[item.row] < item.TextSize.height) {
            rowLocations[item.row] = item.TextSize.height;
            // textHeight[item.row] = TextSize.height;
        }
        if (columnLocations[item.column] < item.TextSize.width) {
            columnLocations[item.column] = item.TextSize.width;
            // textWidth[item.column] = TextSize.width;
        }
        // console.log("行的高度，列的宽度",rowLocations[item.row],columnLocations[item.column])
    });
    calNodeInterval(nodes);
    // console.log("333");
    rowLocations.forEach(function(item) {
        maxHeights.push(item);//文字的最大宽度
    });
    columnLocations.forEach(function(item) {
        maxWidthes.push(item);//文字的最大高度
    });
    //计算节点的坐标、节点文字的坐标
    calNodeLocation(imageName, nodes, nodeHeights, nodeWidthes, maxWidthes);
    // console.log("444");

    let middleRow = rowLocations[0];
    let middleColumn = columnLocations[0];
    rowLocations[0] = 0.5 * nodes[0].TextSize.width;
    columnLocations[0] = rowLocations[0] ;
    //rowLocations每行节点的文字节点左上顶点的纵坐标
    // TODO纵坐标的计算需要考虑节点文字一上一下的情况
    //现在先做全部放在节点上面的情况
    for (let i = 1; i < rowLocations.length; ++i) {
        let middleRow1 = rowLocations[i];
        rowLocations[i] = rowLocations[i - 1] + middleRow + 2*m +globalSettins.nodehight;
        middleRow = middleRow1;
    }
    //columnLocations存放每列节点的文字节点左上顶点的横坐标
    for (let i = 1; i < columnLocations.length; ++i) {
        let middleColumn1 = columnLocations[i];
        columnLocations[i] = columnLocations[i - 1] + middleColumn + m;
        middleColumn = middleColumn1;
    }
}
/*
* 生成node和edges的config
* @param data: nodes或edges数据
*/
function makeConfig(data) {
    let config = JSON.parse(JSON.stringify(defaultConfig));
    // console.log("==== ",data);
    if (data.text_content != null){
        config.text.content = data.text_content;
    }
    if (data.text_color != null){
        config.text.color = data.text_color;
    }
    if (data.color != null){
        config.color = data.color;
    }
    // todo 更新节点状态
    if (data.status != null){
        config.status = data.status;
    }
    return config;
}
// //应急管理中的计算edges的起点或终点的函数
// function findConnectorLocation(connector, columnLocations, rowLocations, maxWidthes, maxHeights, node) {
//     let x = 0;
//     let y = 0;
//     switch (connector) {
//         case 1:
//             x = columnLocations[node.column];
//             y = rowLocations[node.row] + maxHeights[node.row] / 2;
//             return {
//                 x: x,
//                 y: y
//             }
//         case 2:
//             x = columnLocations[node.column] + maxWidthes[node.column] / 2;
//             y = rowLocations[node.row];
//             return {
//                 x: x,
//                 y: y
//             }
//         case 3:
//             x = columnLocations[node.column] + maxWidthes[node.column];
//             y = rowLocations[node.row] + maxHeights[node.row] / 2;
//             return {
//                 x: x,
//                 y: y
//             }
//         case 4:
//             x = columnLocations[node.column] + maxWidthes[node.column] / 2;
//             y = rowLocations[node.row] + maxHeights[node.row];
//             return {
//                 x: x,
//                 y: y
//             }
//     }
// }
//本项目重写的计算edges
function findConnectorLocation(connector, columnLocations, rowLocations, maxWidthes, maxHeights, node) {
    let x = 0;
    let y = 0;
    switch (connector) {
        case 1:
            x = node.x;
            y = node.y + maxHeights[node.row] / 2;
            return {
                x: x,
                y: y
            }
        case 2:
            x = node.x + maxWidthes[node.column] / 2;
            y = node.y;
            return {
                x: x,
                y: y
            }
        case 3:
            x = node.x + maxWidthes[node.column];
            y = node.y + maxHeights[node.row] / 2;
            return {
                x: x,
                y: y
            }
        case 4:
            x = node.x + maxWidthes[node.column] / 2;
            y = node.y + maxHeights[node.row];
            return {
                x: x,
                y: y
            }
    }
}
//每个image两端的节点坐标
function  calStartEnd(imageName,nodes,columnLocations,columnInterval)
{
    let imageNameSize= calNodeTextSize(imageName.length, globalSettins.startNodeLineWordCount, globalSettins.fontSize);//一行只显示一行节点文字的一半数量的imagename
    // console.log("23546",imageName,imageNameSize,globalSettins.startNodeLineWordCount);
    let startNode_x = nodes[0].x - globalSettins.columnSpace - globalSettins.startNodewidth;//减去间隔，减去最开始的竖线的宽度
    let startNode_y = nodes[0].y - 0.5 * (globalSettins.startNodehight - nodes[0].h);//减去间隔，减去最开始的竖线的宽度
    let startNode_tx = startNode_x - 0.5 * imageNameSize.width - globalSettins.imageSpace;//文字的tx是文字的中心点，所以只减去0.5*宽度
    let startNode_ty = 0;

    startNode_ty = nodes[0].y + 0.5 * nodes[0].h;
    // if(imageNameSize.height > nodes[0].h)
    // {
    //     startNode_ty = nodes[0].y - 0.5 * (imageNameSize.height - nodes[0].h);
    // }else{
    //     startNode_ty = nodes[0].y + 0.5 * (nodes[0].h - imageNameSize.height);
    // }
    // console.log("lllll ",nodes[columnLocations.length - 1].x,columnInterval[columnLocations.length - 1],globalSettins.columnSpace,globalSettins.startNodewidth);
    let endNode_x = nodes[columnLocations.length - 1].x + 0.5 * columnInterval[columnLocations.length - 1]  + globalSettins.startNodewidth ;
    let endNode_y = startNode_y;
    return {
        startNode_x,
        startNode_y,
        startNode_tx,
        startNode_ty,
        endNode_x,
        endNode_y
    }
}
//画出每个image两端的节点和连线
//startToEndNode存储起始节点和终止节点的位置信息
function drawImageName(ctx,imageName,nodes,columnLocations,startToEndNode)
{
    drawNode(startToEndNode.startNode_x, startToEndNode.startNode_y, SHAPE.RECTANGULAR, STATUS.DEFAULT, globalSettins.lineWidth, ctx, "#ffffff", "#f3f5f6", globalSettins.startNodehight, globalSettins.startNodewidth);
    drawText(startToEndNode.startNode_tx, startToEndNode.startNode_ty, imageName, globalSettins.font, globalSettins.fontSize, globalSettins.lineSpace, globalSettins.startNodeLineWordCount, ctx);
    drawNode(startToEndNode.endNode_x, startToEndNode.endNode_y, SHAPE.RECTANGULAR, STATUS.DEFAULT, globalSettins.lineWidth, ctx, "#ffffff", "#f3f5f6", globalSettins.startNodehight, globalSettins.startNodewidth);
    ctx.beginPath();
    ctx.lineWidth = globalSettins.lineWidth;
    ctx.strokeStyle = "#ffffff";
    ctx.moveTo(startToEndNode.startNode_x, nodes[0].y + 0.5 * nodes[0].h);
    ctx.lineTo(nodes[0].x, nodes[0].y + 0.5 * nodes[0].h);
    ctx.fillStyle = "#ffffff";
    ctx.fill();
    ctx.stroke();

    ctx.moveTo(nodes[columnLocations.length - 1].x + nodes[columnLocations.length - 1].w, nodes[0].y + 0.5 * nodes[0].h);
    ctx.lineTo(startToEndNode.endNode_x,nodes[0].y + 0.5 * nodes[0].h);
    ctx.fillStyle = "#ffffff";
    ctx.fill();
    ctx.stroke();

}
/*
* 更新单个画布的元素
* @param data: 数据
* @param canvas: 画布(bom)对象
*/
function updateElements(imageName,nodesData, edgesData,canvas) {

    // 用于存放每行节点的文字左上顶点的纵坐标
    let rowLocations = [];
    // 用于存放每列节点的文字节点左上顶点的横坐标
    let columnLocations = [];
    // 用于存放每列最大宽度
    let maxWidthes = [];
    // 用于存放每行最大高度
    let maxHeights = [];
    let nodeWidthes = [];
    let nodeHeights = [];
    findNodeInfo(imageName, nodesData, rowLocations, columnLocations, maxWidthes, maxHeights, nodeWidthes, nodeHeights);
    // console.log("hhhh");

    clearDraw();
    nodesData.forEach(function(item) {
        // console.log("节点左上x和y:",item.x,item.y,);
        new myNode(item.nodeId,
            item.x,//node的位置x
            item.y,//node的位置y
            nodeWidthes[item.column],//node的宽
            nodeHeights[item.row],//node的高
            item.tx,
            item.ty,
            item.TextSize.width,
            item.TextSize.height,
            item.type,
            item.varName,
            item.text,
            makeConfig(item));
    });

    edgesData.forEach(function(item) {
        // console.log("节点：",item.edgeId,nodes[item.nodeId]);
        // console.log("最大的宽和高：",maxWidthes,maxHeights);
        // console.log("宽和高：",nodeWidthes,nodeHeights);
        // console.log(columnLocations)

        let startPoint = findConnectorLocation(item.startConnector,
            columnLocations,
            rowLocations,
            // maxWidthes,
            // maxHeights,
            nodeWidthes,// nodeWidthes[nodes[item.nodeId].column],
            nodeHeights,// nodeHeights[nodes[item.nodeId].row],
            nodesData[item.nodeId]);
        let endPoint = findConnectorLocation(item.endConnector,
            columnLocations,
            rowLocations,
            // maxWidthes,
            // maxHeights,
            nodeWidthes,// nodeWidthes[nodes[item.nodeId].column],
            nodeHeights,// nodeHeights[nodes[item.nodeId].row],
            nodesData[item.target]);
        let middlePoint ={
            x:0,
            y:0
        }
        if ( (startPoint.y === endPoint.y && startPoint.x !== endPoint.x) || (startPoint.y !== endPoint.y && startPoint.x === endPoint.x)) {
            middlePoint.x = startPoint.x;
            middlePoint.y = startPoint.y;
        }else{
            if ( startPoint.y < endPoint.y ) {
                middlePoint.x = startPoint.x + 0.5 * columnInterval[nodesData[item.nodeId].column];//每列的宽度间隔一样的所以选择一个就行
                middlePoint.y = startPoint.y;
            } else {
                middlePoint.x = endPoint.x - 0.5 * columnInterval[nodesData[item.nodeId].column];
                middlePoint.y = startPoint.y;
            }
        }
        // console.log("columnInterval:", item.edgeId,item.nodeId,nodesData[item.nodeId].column);
        new myEdge(startPoint.x,
            startPoint.y,
            middlePoint.x,
            middlePoint.y,
            endPoint.x,
            endPoint.y,
            item.startConnector,
            item.endConnector,
            makeConfig(item));
        // addNodeRelation(item.nodeId, item.target, item.text_content);
    });
    // setStatus(nodes[currentNodeId], STATUS.STOP);
    // console.log("qqqq",columnInterval)

    let startToEndNode = calStartEnd(imageName,nodes,columnLocations,columnInterval);
    let ctx = canvas.getContext("2d");
    // console.log("columnLocations[]",columnLocations.length-1,columnLocations[columnLocations.length-1],maxWidthes[maxWidthes.length-1]);
    // canvas.width = columnLocations[columnLocations.length-1] + maxWidthes[maxWidthes.length-1] + 30+500;
    canvas.width = startToEndNode.endNode_x + globalSettins.startNodewidth + globalSettins.whiteSpace;
    // console.log("oooo ",imageName,canvas.width);
    canvas.height = calImageHeight(nodes,10);
    // console.log("234454 ",canvas.width, canvas.height);
    // ctx.translate(0,150);
    // console.log("nodesdata:", nodesData);
    ctx.fillStyle = '#f3f5f6';
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    ctx.clearRect(0,0, canvas.width, canvas.height);

    drawImageName(ctx,imageName,nodes,columnLocations,startToEndNode);
    // console.log("123444",nodes);

    nodes.forEach(function(item) {
        // item.draw(ctx);
        // TODO 需要根据画节点的接口函数修改一下
        // console.log(item);
        drawNode(item.x, item.y, SHAPE.RECTANGULAR, item.config.status, globalSettins.lineWidth, ctx, "#111111", "#f3f5f6", item.h, item.w);
        // console.log("画节点： ",item.x, item.y);
        // drawText()
        // console.log("画文字： ",item.tx, item.ty, item.text);
        drawText(item.tx, item.ty, item.text, globalSettins.font, globalSettins.fontSize, globalSettins.lineSpace, globalSettins.lineWordCount, ctx);
    });
    edges.forEach(function(item) {
        // item.draw(ctx);
        // console.log("edges",item.start_x, item.start_y, item.middle_x, item.middle_y, item.end_x, item.end_y);
        drawLine1(item.start_x, item.start_y, item.middle_x, item.middle_y, item.end_x, item.end_y, item.startConnector, item.endConnector, ctx);
    });
}
// //更新一个场景下的多个画布
// function updateElements(images,canvas) {
//     console.log(images.length);
//     // updateCanvs(images[0].nodes, images[0].edges, canvas);
//     // for (let i = 0;i < images.length;i++){
//     //     updateCanvs(images[i].nodes, images[i].edges, canvas);
//     // }
//
//     images.forEach(function(item) {
//         console.log("节点左上x和y:", item.x, item.y,);
//         updateCanvs(item.nodes, item.edges, canvas);
//     });
//
// }

// /*
// * 绘制元素
// * @param canvas: 画布对象
// */
// function drawElements(canvas){
//     let ctx = canvas.getContext("2d");
//     nodes.forEach(function(item) {
//         // item.draw(ctx);
//         // TODO 需要根据画节点的接口函数修改一下
//         drawNode(item.x, item.y, SHAPE.RECTANGULAR, STATUS.TRUE, globalSettins.lineWidth, ctx, "#f3f5f6", "#f3f5f6", item.h, item.w);
//         // drawText()
//         // drawText(item.tx, item.y, item.text, globalSettins.fontSize, globalSettins.lineSpace, globalSettins.lineWordCount, ctx);
//
//     });
//     // edges.forEach(function(item) {
//     //     // item.draw(ctx);
//     //     // drawLine(item.start_x, item.start_y, item.end_x, item.end_y, item.startConnector, item.endConnector, ctx);
//     // });
// }
export {
    initCanvas,
    updateElements,
    // drawElements,
    clearDraw,
    // changeElemStatus,
    // registerClick,
    // getVarMapLine,
}